
<template>
  <el-form-item
    :key="element.metaRefresh"
    :prop="itemProp"
    :label="element.options.label"
    :rules="element.options.rules"
  >
    <el-input
      v-model="element.options.value"
      @change="inputChange"
      @focus="inputFocus"
      placeholder="请输入内容"
    />
  </el-form-item>
</template>
 
<script lang="ts">
import {
  defineComponent,
  ref,
  inject,
  watch,
  toRefs,
  reactive,
  computed,
} from "vue";
import type { LowCodeImp } from "@/components/low-code/core/type";
export default defineComponent({
  name: "inputWidget",
  props: ["element"],
  setup(props) {
    const getLowCodeInstance = inject("getLowCodeInstance") as Function;
    const lowCode: LowCodeImp = getLowCodeInstance();
    const { element } = toRefs(props);
    const inputChange = () => {
      element.value.options.onChangeEvents.map(async (code: any) => {
        await lowCode.eventCenterController.fire(code);
      });
    };
    const inputFocus = () => {
      element.value.options.onFocusEvents.map(async (code: any) => {
        await lowCode.eventCenterController.fire(code);
      });
    };

    const itemProp = computed(() => {
      if (element.value.model && element.value.model.length > 0) {
        return element.value.model[element.value.model.length - 1];
      }
      return "";
    });

    // watch(reactive(element.value.options), (options) => {
    //   if (options.eventTriggerType == "watch") {
    //     element.value.options.eventCode.map((code: any) => {
    //       lowCode.eventCenterController.fire(code);
    //     });
    //   }
    // });

    return {
      element,
      itemProp,
      inputChange,
      inputFocus,
    };
  },
});
</script>

<style  scoped>
</style>
